(function () {
    "use strict";

    angular.module('core').factory('romaneioService', factory);
    factory.$inject = ['$http', '$q'];

    function factory($http, $q) {

        var _get = function (id) {
            var deferred = $q.defer();
            $http.post('/romaneio/get', id)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };
        var _getAll = function (args) {
            var deferred = $q.defer();
            $http.post('/romaneio/getall', args)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };
        var _count = function (args) {
            var deferred = $q.defer();
            $http.post('/romaneio/count', args)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };
        var _prepare = function (args) {
            var deferred = $q.defer();
            $http.post('/romaneio/Prepare', args)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        }
        var _save = function (item) {
            var deferred = $q.defer();
            $http.post('/romaneio/save', item)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };
        var _SetEncerrada = function (item) {
            var deferred = $q.defer();
            $http.post('/romaneio/SetEncerrada', item)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };
        var _prepareNewItem = function (args) {
            var deferred = $q.defer();
            $http.post('/romaneio/PrepareNewItem',args)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        }
        var _prepareNew = function () {
            var deferred = $q.defer();
            $http.post('/romaneio/PrepareNew')
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        }
        var _delete = function (id) {
            var deferred = $q.defer();
            $http.post('/romaneio/delete', id)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };

        return {
            get: _get,
            getAll: _getAll,
            count: _count,
            save: _save,
            delete: _delete,
            prepareNewItem: _prepareNewItem,
            prepare: _prepare,
            SetEncerrada: _SetEncerrada,
            prepareNew: _prepareNew
        };
    }

})();


